package com.ax.utils;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;
    protected static final String MESSAGE = "message";

    
	
	
    protected PrintWriter out;
    
	
	public void setServletResponse(HttpServletResponse arg0)
	{
		this.response=arg0;
		try {
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html; charset=UTF-8");
			out=arg0.getWriter();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void setServletRequest(HttpServletRequest arg0)
	{
	    this.request=arg0;	
	    this.session=request.getSession();
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}
	public HttpSession getSession() {
		return session;
	}
	
	public Integer getUserId(){
		return (Integer)session.getAttribute(Keys.USER_ID);
	}
	
	public Integer getUserLevel(){
		return (Integer)session.getAttribute(Keys.USER_LEVEL);
	}
	
	public String getUserName(){
		return (String)session.getAttribute(Keys.USER_NAME);
	}
}
